//
//  KeChengDetailVC.m
//  ZhiBoYuan
//
//  Created by apple on 2018/5/4.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "KeChengDetailVC.h"
#import "KeChengDaGangViewController.h"
#import "KeChengXiangQingVC.h"

#import "KeChengPingLunVC.h"
#import "SuiTangLianXiVC.h"
#import "ChongZhiViewController.h"


#import "IgnoreHeaderTouchAndRecognizeSimultaneousTableView.h"
#import "AppDelegate.h"

#import "JShareTool.h"

//#define  KTopBarHeight 64.
//#define  imageHight 200
#define  MenuHeight 40

#define  BottomButtonHeight 50

#import "CKSlideMenu.h"


@interface KeChengDetailVC ()
<
UITableViewDelegate,
UITableViewDataSource
>
{
    KeChengDaGangViewController *daGangVc;
    SuiTangLianXiVC *DVC;
    
    CGFloat imageHight;
    
}
@property (nonatomic , strong) IgnoreHeaderTouchAndRecognizeSimultaneousTableView * tableView;
@property (nonatomic, assign) BOOL canScroll;
@property (nonatomic, assign) BOOL isTopCanNotMoveTableView;
@property (nonatomic, assign) BOOL isTopCanNotMoveTableViewPre;
@property (nonatomic, strong) CKSlideMenu *slideMenu;
@property (nonatomic, strong) UITableViewCell  *cell;


@property(nonatomic, strong)UIButton *aButton;
@property(nonatomic, strong)UIButton *bButton;

@property(nonatomic, strong)UIButton *topButton;

@property(nonatomic,strong)NSMutableArray *vcArr;
@property(nonatomic,strong)NSArray *nameArr;

@property (nonatomic,strong)UIImageView *headImage;

@property (nonatomic, strong) UIView *headerBackView;


@property (nonatomic, strong) UIView *mengView;



@property (nonatomic, assign)BOOL xuedouIsGou;//学豆够不够
@property (nonatomic, assign)int price;

@property(nonatomic,assign)NSInteger index;


@property (nonatomic, strong)UIAlertView *alertView;// 跳转答题

@property (nonatomic, copy)NSString *video_id;//答完题播放视频需要

@end

@implementation KeChengDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    imageHight = screenWidth/16*9;
    
    _index = 0;
    [self.view addSubview:self.tableView];

    [self.view addSubview:self.aButton];
    
    [self.view addSubview:self.bButton];
    
    
//   //////////   rself.course_id = @"14";
    
    
    [((AppDelegate *)[UIApplication sharedApplication].delegate).window addSubview:self.topButton];
    
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"分享-3"] style:(UIBarButtonItemStyleDone) target:self action: @selector(shere)];
    
    self.navigationItem.rightBarButtonItems= @[item];
    
     [self loadKeData];
    

    
    
}


#pragma mark ----------------------- 湖区课数据 ------------------------
-(void)loadKeData{
    
    
    [MBProgressHUD showLoadingImageToView:self.view];
    
    
    SGParameter *parameter  = [[SGParameter alloc] init];
    parameter.body = @{
                       @"course_id":self.course_id// 1 直播 2微课 3套餐
                       };
    
    [SGHttpTool POST:[NSString stringWithFormat:@"%@g=Client&m=Course&a=miniCourseInfo",HTTPP] parameter:parameter sucess:^(id responseObject) {
        NSLog(@"%@",responseObject);
        NSDictionary *dic = responseObject;
        if ([dic[@"status"] intValue] == 200) {
            
            [_headImage sd_setImageWithURL:[NSURL URLWithString:[dic[@"data"][@"course_info"] valueForKey:@"image_url"]] placeholderImage:[UIImage imageNamed:@"lessonPlace"]];
            
            _price = [[dic[@"data"][@"course_info"] valueForKey:@"price"] intValue];
            
            if ([[dic[@"data"] valueForKey:@"had_collect"]intValue] == 1) {
                //已收藏
                [_aButton setTitle:@"取消收藏" forState:0];
            }else{
                [_aButton setTitle:@"加入收藏" forState:0];
            }
            
            if (Teacher) {
                [_bButton setTitle:@"进入学习" forState:0];
            }else{
                if ([[dic[@"data"] valueForKey:@"had_buy"]intValue] == 1) {
                    //已购买
                    [_bButton setTitle:@"进入学习" forState:0];
                }else{
                    [_bButton setTitle:@"加入学习" forState:0];
                }
                
            }
            
            
            [MBProgressHUD hideHUDForView:self.view animated:YES];
            
        }else{
            [MBProgressHUD showTextOnly:self.view message:dic[@"msg"] delay:2.0f];
        }
        
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        
    }];
    
}

#pragma mark ----------------------- 获取课程详情 ------未调用------------------
- (void)downloadCourseDetailDatas{
    
     [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
//    [MBProgressHUD showLoadingImageToView:self.view];
    
    SGParameter *parameter  = [[SGParameter alloc] init];
    parameter.body = @{
                       @"course_id" : self.course_id// 1 直播 2微课 3套餐
                       };
    [SGHttpTool POST:Host_Append(CourseList) parameter:parameter sucess:^(id responseObject) {
        //成功回调
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:responseObject options:NSJSONWritingPrettyPrinted error:nil];
        NSString *resultStr =[[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
        ZYLog(@"%@",resultStr);
        //        SGReceive *receive = [SGReceive receiveWithResponseObject:responseObject dataWord:@"course_list" dataClass:[MicroCourseModel class]];
        //        [self.dataArray addObjectsFromArray:receive.data];
        //        [self.tableView reloadData];
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        
    }];
    
}

#pragma mark ----------------------- 加入收藏 ------------------------
-(void)saveSomth{
    
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
   
//    [MBProgressHUD showLoadingImageToView:self.view];

    
    if ([_aButton.titleLabel.text isEqualToString:@"加入收藏"]) {
        //加入收藏
        SGParameter *parameter  = [[SGParameter alloc] init];
        parameter.body = @{ @"course_id":self.course_id
                            // 1 直播 2微课 3套餐
                           };
        
        [SGHttpTool POST:[NSString stringWithFormat:@"%@g=Client&m=Collect&a=addCourse",HTTPP] parameter:parameter sucess:^(id responseObject) {
            NSLog(@"%@",responseObject);
            
            NSDictionary *dic = responseObject;
            
            if ([dic[@"status"] intValue] == 200) {
                [MBProgressHUD showTextOnly:self.view message:@"收藏成功" delay:2.0f];
                [_aButton setTitle:@"取消收藏" forState:0];
                
            }else{
                [MBProgressHUD showTextOnly:self.view message:dic[@"msg"] delay:2.0f];
            }
            
        } failure:^(NSError *error) {
            NSLog(@"%@",error);
            [MBProgressHUD hideHUDForView:self.view animated:YES];
            
        }];
        
    }else{
        //取消收藏
        SGParameter *parameter  = [[SGParameter alloc] init];
        parameter.body = @{@"course_id":self.course_id,
                           };
        
        [SGHttpTool POST:[NSString stringWithFormat:@"%@g=Client&m=Collect&a=delCourse",HTTPP] parameter:parameter sucess:^(id responseObject) {
            NSLog(@"%@",responseObject);
            NSDictionary *dic = responseObject;
            
            if ([dic[@"status"] intValue] == 200) {
                [MBProgressHUD showTextOnly:self.view message:dic[@"msg"] delay:2.0f];
                
                [_aButton setTitle:@"加入收藏" forState:0];
                
            }else{
                [MBProgressHUD showTextOnly:self.view message:dic[@"msg"] delay:2.0f];
            }
            
        } failure:^(NSError *error) {
            NSLog(@"%@",error);
            [MBProgressHUD hideHUDForView:self.view animated:YES];
            
        }];
        
    }
    
}


#pragma mark ----------------------- 加入学习 ------------------------
-(void)addToStudyAction{
    
    if (Teacher) {
        //学习
        [daGangVc startLearning];
    }else{
        
        if ([_bButton.titleLabel.text isEqualToString:@"加入学习"]) {
            
            NSString *totalDou = [ZYUserManager userInfo].left_xuedou;
            int dou = _price;
            
            if (dou == 0) {
                
                SGParameter *parameter  = [[SGParameter alloc] init];
                NSLog(@"%@",self.course_id);
                parameter.body = @{
                                   @"course_id":self.course_id// 1 直播 2微课 3套餐
                                   };
                
                [SGHttpTool POST:[NSString stringWithFormat:@"%@g=Client&m=Order&a=buyCourse",HTTPP] parameter:parameter sucess:^(id responseObject) {
                    NSLog(@"%@",responseObject);
                    
                    NSDictionary *dic = responseObject;
                    
                    if ([dic[@"status"] intValue] == 200) {
                        if ([dic[@"data"][@"status"] intValue] == 1) {
                            [MBProgressHUD showTextOnly:self.view message:@"加入成功" delay:2.0f];
                            [_bButton setTitle:@"进入学习" forState:0];
                            DVC.buyState = 1;
                            
                        }else{
                            [MBProgressHUD showTextOnly:self.view message:dic[@"data"][@"msg"] delay:2.0f];

                        }
                        
                    }else{
                        [MBProgressHUD showTextOnly:self.view message:dic[@"msg"] delay:2.0f];
                    }
                    
                } failure:^(NSError *error) {
                    NSLog(@"%@",error);
                    
                }];
                
            }else{
                
                NSString *message1 = [NSString stringWithFormat:@"您确定使用%d个学豆？",dou];
                
                if ([totalDou intValue] >= dou) {
                    _xuedouIsGou = YES;
                    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:message1 delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil, nil];
                    [alertView show];
                }else{
                    _xuedouIsGou = NO;
                    NSString *str = [NSString stringWithFormat:@"您的学豆不足，是否去充值？",totalDou];
                    
                    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:str delegate:self cancelButtonTitle:@"否" otherButtonTitles:@"是", nil, nil];
                    [alertView show];
                }
            }
            
            
        }else{
            //学习
            [daGangVc startLearning];
            
        }
        
    }
    
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (alertView.tag == 999) {
        if (buttonIndex) {
            [DVC startToAnswer:self.video_id];
        }
        return;
    }
    
    
    if (buttonIndex == 0) {
        
    }else if (buttonIndex == 1){
        
        if (_xuedouIsGou == YES) {
            
            SGParameter *parameter  = [[SGParameter alloc] init];
            NSLog(@"%@",self.course_id);
            parameter.body = @{
                               @"course_id":self.course_id// 1 直播 2微课 3套餐
                               };
            
            [SGHttpTool POST:[NSString stringWithFormat:@"%@g=Client&m=Order&a=buyCourse",HTTPP] parameter:parameter sucess:^(id responseObject) {
                NSLog(@"%@",responseObject);
                
                NSDictionary *dic = responseObject;
                
                if ([dic[@"status"] intValue] == 200) {
                    if ([dic[@"data"][@"status"] intValue] == 1) {
                        [MBProgressHUD showTextOnly:self.view message:@"加入成功" delay:2.0f];
                        [_bButton setTitle:@"进入学习" forState:0];
                        DVC.buyState = 1;

                    }else{
                        [MBProgressHUD showTextOnly:self.view message:dic[@"data"][@"msg"] delay:2.0f];

                        
                    }
                    
                }else{
                    [MBProgressHUD showTextOnly:self.view message:dic[@"msg"] delay:2.0f];
                }
                
            } failure:^(NSError *error) {
                NSLog(@"%@",error);
                
            }];
        }else{

            
             ChongZhiViewController *chongVC = [[ChongZhiViewController alloc]init];
            
            
            [Helper setMoRenNav:self.navigationController];
            [Helper setNavColorFrom:self.navigationController color:ZhuTiColor];

            [self.navigationController pushViewController:chongVC animated:YES];
//            [Helper setMoRenNav:nvc];
//            [Helper setNavColorFrom:nvc color:ZhuTiColor];
//            [self presentViewController:nvc animated:YES completion:^{
            
//            }];
            
        }
        
    }
    
    
}


#pragma mark ----------------------- 分享 ------------------------
-(void)shere{
    [MBProgressHUD showLoadingImageToView:self.view];
    SGParameter *parameter  = [[SGParameter alloc] init];
    parameter.body = @{
                       @"course_id":self.course_id// 1 直播 2微课 3套餐
                       };
    [SGHttpTool POST:Host_Append(GetCoureShareInfo) parameter:parameter sucess:^(id responseObject) {
        
        NSLog(@"%@",responseObject);
        
        NSDictionary *dic = responseObject;
        if ([dic[@"status"] intValue] == 200) {
//            [JShareTool setupJShareConfig];

            NSDictionary *shareInfo  = dic[@"data"][@"share_info"];
            JSHAREMessage *message = [JSHAREMessage message];
            message.mediaType = JSHARELink;
            message.url = shareInfo[@"link_url"];
            message.text = shareInfo[@"desc"];
            message.title = shareInfo[@"title"];
            NSString *imageURL = shareInfo[@"img_url"];
            NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageURL]];
            
            message.image = imageData;
            message.thumbnail = imageData;

            [MBProgressHUD hideHUDForView:self.view animated:YES];

            [JShareTool shareViewAddSuperview:[UIApplication sharedApplication].keyWindow withMessage:message];
            
        }else{
            
            [MBProgressHUD showTextOnly:self.view message:dic[@"msg"] delay:2.0f];
        }
        
        

        
    } failure:^(NSError *error) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        
    }];
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    [Helper setMoRenNav:self.navigationController];
    
    if (_isTopCanNotMoveTableView == YES)
    {
        [Helper setNavColorFrom:self.navigationController color:ZhuTiColor ];
    }  else  {
        [Helper setNavColorFrom:self.navigationController color:[UIColor clearColor]];
    }
    
    
    [IQKeyboardManager sharedManager].enable = NO;

    
     [self topButtonManager];
    
    
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    

    
    [IQKeyboardManager sharedManager].enable = YES;
    
    
     [self.topButton setHidden:YES];
    [Helper setMoRenNav:self.navigationController];
    [Helper setNavColorFrom:self.navigationController color:ZhuTiColor];
    
    
    
}

- (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    
    [Helper setMoRenNav:self.navigationController];
    [Helper setNavColorFrom:self.navigationController color:ZhuTiColor];

    
}





-(UIButton *)topButton
{
    if (!_topButton)
    {
        _topButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _topButton.frame = CGRectMake(SCREEN_WIDTH-60, SCREEN_HEIGHT-BottomButtonHeight-50-HOME_INDICATOR_HEIGHT, 40, 40);
        [_topButton setBackgroundImage:[UIImage imageNamed:@"组3副本"] forState:(UIControlStateNormal)];
        
        _topButton.layer.masksToBounds = YES;
        
        _topButton.layer.cornerRadius = _topButton.frame.size.width/2 ;
        
        [_topButton setBackgroundColor:[UIColor whiteColor]];
        
        [_topButton addTarget:self action:@selector(top:) forControlEvents:(UIControlEventTouchUpInside)];
        
        
        _topButton.layer.borderWidth = 1;

        _topButton.layer.borderColor = hui1Color.CGColor;
        
        
    }
    return _topButton;
}


#pragma mark -----------------------  回到顶部 --- 评论  ------------------------
-(void)top:(UIButton *)sender
{
    
    if (_index == 0)
    {
        NSLog(@"top");
        
        KeChengDaGangViewController *tableVC  = self.vcArr[0];

        [tableVC topSender:nil];
        
    }
    else
    {
        NSLog(@"评论");
        
        KeChengPingLunVC *tableVC  = self.vcArr[2];

        [tableVC pingLunSender:nil];
    }
    
}


-(void)topButtonManager{
    if (_index == 0 )
    {
        [self.topButton setBackgroundImage:[UIImage imageNamed:@"组3副本"] forState:(UIControlStateNormal)];
        
        [self.topButton setHidden:NO];
    }
    else if (_index == 2 )
    {
        [self.topButton setBackgroundImage:[UIImage imageNamed:@"组4"] forState:(UIControlStateNormal)];
        [self.topButton setHidden:NO];
    }
    else
    {
        [self.topButton setHidden:YES];
    }
}

-(UIButton *)bButton
{
    if (!_bButton)
    {
        _bButton=[UIButton buttonWithType:(UIButtonTypeCustom)];
        _bButton.frame =CGRectMake(SCREEN_WIDTH/2, SCREEN_HEIGHT-50-HOME_INDICATOR_HEIGHT, SCREEN_WIDTH/2, BottomButtonHeight) ;
        

        [_bButton setBackgroundColor:ZhuTiColor];
        
        [_bButton setTitle:@"加入学习" forState:0];
        
        [_bButton addTarget:self action:@selector(addToStudyAction) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _bButton;
}


- (UIButton *)aButton
{
    if (!_aButton)
    {
        _aButton=[UIButton buttonWithType:(UIButtonTypeCustom)];
        _aButton.frame = CGRectMake(0, SCREEN_HEIGHT-50-HOME_INDICATOR_HEIGHT , SCREEN_WIDTH/2, BottomButtonHeight);
        [_aButton setBackgroundColor:[UIColor whiteColor]  ];
        
        [_aButton setTitle:@"加入收藏" forState:UIControlStateNormal];
        
        [_aButton addTarget:self action:@selector(saveSomth) forControlEvents:(UIControlEventTouchUpInside)];
        
        [_aButton setTitleColor:ZhuTiColor forState:(UIControlStateNormal)];
        
        _aButton.layer.borderColor = ZhuTiColor.CGColor;
        
        _aButton.layer.borderWidth = 1;
        
    }
    return _aButton;
}

- (void)acceptMes:(NSNotification *)notification
{
    NSDictionary *userInfo = notification.userInfo;
    NSString *canScroll = userInfo[NotificationCanScroll];
    if ([canScroll isEqualToString:@"1"])
    {
        _canScroll = YES;
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return CGRectGetHeight(self.view.frame);
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.cell.contentView addSubview:self.slideMenu];
    return self.cell;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    
    //-----------------------------------------------
    //图片高度
    CGFloat imageHeight = self.headerBackView.frame.size.height;
    //图片宽度
    CGFloat imageWidth = SCREEN_WIDTH;
    //图片上下偏移量
    CGFloat imageOffsetY = scrollView.contentOffset.y;
    
//    NSLog(@"图片上下偏移量 imageOffsetY:%f ->",imageOffsetY);
    
    //上移
    if (imageOffsetY < 0)
    {
        CGFloat totalOffset = imageHeight + ABS(imageOffsetY);
        CGFloat f = totalOffset / imageHeight;
        
//        self.headImage.frame = CGRectMake(-(imageWidth * f - imageWidth) * 0.5, imageOffsetY, imageWidth * f, totalOffset);
//        self.mengView.frame = self.headImage.bounds;
    }
    
    //-----------------------------------------------
    
    CGFloat tableViewOffsetY = [_tableView rectForSection:0].origin.y - NAVIGATION_BAR_HEIGHT;
    CGFloat contentOffsetY = scrollView.contentOffset.y;
    
    _isTopCanNotMoveTableViewPre = _isTopCanNotMoveTableView;
    
    if (contentOffsetY >= tableViewOffsetY)
    {
        scrollView.contentOffset = CGPointMake(0, tableViewOffsetY);
        _isTopCanNotMoveTableView = YES;

        [Helper setNavColorFrom:self.navigationController color:ZhuTiColor];
    }
    else
    {
        _isTopCanNotMoveTableView = NO;
        
        CGFloat alpha = scrollView.contentOffset.y/imageHight;
        if (alpha > 1)
        {
            alpha = 1;
        }

        [Helper setNavColorFrom:self.navigationController color:ZhuTiColorAlpha(alpha)]; //RGB(76,186,198)
    }
    
    if (_isTopCanNotMoveTableViewPre != _isTopCanNotMoveTableView)
    {
        if (_isTopCanNotMoveTableView && !_isTopCanNotMoveTableViewPre)
        {
            [[NSNotificationCenter defaultCenter] postNotificationName:TABLETOP object:nil userInfo:@{NotificationCanScroll: @"1"}];
            _canScroll = NO;
        }
        
        if (_isTopCanNotMoveTableViewPre && !_isTopCanNotMoveTableView)
        {
            //轻
            if (!_canScroll)
            {
                scrollView.contentOffset = CGPointMake(0, tableViewOffsetY);
            }
            
        }
        
    }
    
}





-(UIView *)headerBackView
{
    if (!_headerBackView)
    {
        _headerBackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, imageHight-NAVIGATION_BAR_HEIGHT)];
        [_headerBackView setBackgroundColor:[UIColor whiteColor]];
    }
    return _headerBackView;
}


-(UIImageView *)headImage{
    if(!_headImage){
        _headImage = [[UIImageView alloc]initWithFrame: self.headerBackView.bounds];
        
        _headImage.frame  = CGRectMake(0, -NAVIGATION_BAR_HEIGHT, SCREEN_WIDTH, imageHight) ;

        _headImage.image = [UIImage imageNamed:@"lessonPlace"];
    }
    return _headImage;
}

-(UIView *)mengView
{
    if (!_mengView)
    {
        _mengView = [[UIView alloc]initWithFrame:self.headerBackView.bounds];
        _mengView.backgroundColor = RGBA(1, 1, 1, 0.1);
    }
    return _mengView;
}

- (IgnoreHeaderTouchAndRecognizeSimultaneousTableView *)tableView
{
    if (!_tableView)
    {
        _tableView = [[IgnoreHeaderTouchAndRecognizeSimultaneousTableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, CGRectGetHeight(self.view.frame)-BottomButtonHeight) style:UITableViewStylePlain];

        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.showsVerticalScrollIndicator = NO;
        
        _tableView.tableHeaderView = self.headerBackView;
        [self.headerBackView addSubview:self.headImage];
        [self.headImage addSubview:self.mengView];
        
        self.mengView.frame = self.headImage.bounds;
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(acceptMes:) name:TABLELEAVETOP object:nil];
        
    }
    return _tableView;
}


-(UITableViewCell *)cell
{
    if (!_cell)
    {
        _cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
        _cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return _cell;
}

-(CKSlideMenu *)slideMenu
{
    if (!_slideMenu)
    {
        
        _slideMenu = [[CKSlideMenu alloc]initWithFrame:CGRectMake(0 , 0 , SCREEN_WIDTH , MenuHeight)  titles:self.nameArr controllers:self.vcArr];
        _slideMenu.bodyFrame = CGRectMake(0, MenuHeight, SCREEN_WIDTH , SCREEN_HEIGHT - MenuHeight - NAVIGATION_BAR_HEIGHT-BottomButtonHeight);
        _slideMenu.bodySuperView = self.cell;
        _slideMenu.indicatorOffsety = 2;
        _slideMenu.indicatorWidth = ScreenWidth/4-SNRealValue(20);//ScreenWidth/4-5
        _slideMenu.font = [UIFont systemFontOfSize:17];
        _slideMenu.titleStyle     = SlideMenuTitleStyleGradient;
        _slideMenu.indicatorStyle = SlideMenuIndicatorStyleNormal;
        _slideMenu.isFixed = YES;
        _slideMenu.showLine = YES;
        _slideMenu.selectedColor   = ZhuTiColor;
        _slideMenu.indicatorColor  = ZhuTiColor;
        _slideMenu.unselectedColor = [UIColor grayColor];
        
        
        __weak __typeof(&*self)weakSelf = self;
        
        _slideMenu.currentPage = ^(NSInteger index) {
            
            NSLog(@"index = %zd",index);
            
            _index = index;
            
            
            [weakSelf topButtonManager];
            
//            if (_index == 0 )
//            {
//                [weakSelf.topButton setBackgroundImage:[UIImage imageNamed:@"组3副本"] forState:(UIControlStateNormal)];
//
//                [weakSelf.topButton setHidden:NO];
//            }
//            else if (_index == 2 )
//            {
//                [weakSelf.topButton setBackgroundImage:[UIImage imageNamed:@"组4"] forState:(UIControlStateNormal)];
//                [weakSelf.topButton setHidden:NO];
//            }
//            else
//            {
//                [weakSelf.topButton setHidden:YES];
//            }
        };
        
    }
    return _slideMenu;
}
-(NSMutableArray *)vcArr{
    if (!_vcArr) {
        _vcArr = [NSMutableArray array];
        
        daGangVc = [[KeChengDaGangViewController alloc]initWithNibName:@"KeChengDaGangViewController" bundle:nil];
        daGangVc.course_id = self.course_id;

        
        [_vcArr addObject:daGangVc];
        KeChengXiangQingVC *Bvc =[[KeChengXiangQingVC alloc]initWithNibName:@"KeChengXiangQingVC" bundle:nil];
        Bvc.course_id = self.course_id;
        [_vcArr addObject:Bvc];
        
        KeChengPingLunVC *CVC =[[KeChengPingLunVC alloc]initWithNibName:@"KeChengPingLunVC" bundle:nil];
        CVC.course_id = self.course_id;
        [_vcArr addObject:CVC];
        
        DVC =[[SuiTangLianXiVC alloc]initWithNibName:@"SuiTangLianXiVC" bundle:nil];
        DVC.course_id = self.course_id;
        [_vcArr addObject:DVC];
        
        __weak typeof(self) weakSelf = self;

        //看完视频去做题
        [daGangVc setClickToAnswer:^(NSString *video_id) {
            if (Teacher) {
                return;
            }
            weakSelf.video_id = video_id;
            weakSelf.alertView.message = [NSString stringWithFormat:@"视频播放完毕是否开始答题？"];
            [weakSelf.alertView show];
            
        }];
    }
    return _vcArr;
}




- (UIAlertView *)alertView {
    if (_alertView == nil) {
        _alertView = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        _alertView.tag = 999;
    }
    return _alertView;
}



-(NSArray *)nameArr
{
    if (!_nameArr)
    {
        _nameArr =@[@"课程大纲",@"课程详情",@"课程评论",@"随堂练习"];
    }
    return _nameArr;
}

//-(void)viewDidDisappear:(BOOL)animated{
//    [super viewDidDisappear:animated];
//
//}
//
//-(void)dealloc
//{
//
//}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
